package com.pl.handler;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * 使用线程池的异步任务
 *
 * @author shent
 */
@Component
public class ThreadConsumer {

    @Async("MyThreadPool")
    public void myThread() {
        System.out.println(Thread.currentThread().getName());
        int a = 20 / 0;
    }

    @Async("MyThreadPool")
    public Future<String> myThread1() {
        System.out.println(Thread.currentThread().getName());
        return new AsyncResult<>("hello world");
    }
}
